package cn.jjxx.modules.screen.controller;

import cn.jjxx.core.common.data.DuplicateValid;
import cn.jjxx.core.model.AjaxJson;
import cn.jjxx.core.model.PageJson;
import cn.jjxx.core.model.ValidJson;
import cn.jjxx.core.query.annotation.PageableDefaults;
import cn.jjxx.core.query.data.PropertyPreFilterable;
import cn.jjxx.core.query.data.Queryable;
import cn.jjxx.core.query.utils.QueryableConvertUtils;
import cn.jjxx.core.query.wrapper.EntityWrapper;
import cn.jjxx.core.security.shiro.authz.annotation.RequiresMethodPermissions;
import cn.jjxx.core.utils.MessageUtils;
import cn.jjxx.core.utils.ObjectUtils;
import cn.jjxx.core.utils.StringUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializeFilter;
import com.baomidou.mybatisplus.annotations.TableName;
import com.beust.jcommander.internal.Lists;

import org.framework.superutil.thirdparty.excel.ExcelDataFormatter;
import org.framework.superutil.thirdparty.excel.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import cn.jjxx.core.common.controller.BaseBeanController;
import cn.jjxx.core.security.shiro.authz.annotation.RequiresPathPermission;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.apache.commons.fileupload.disk.DiskFileItem;
import org.framework.superutil.thirdparty.excel.ExcelUtils;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import cn.jjxx.modules.common.bean.UploadExcel;
import cn.jjxx.modules.sys.entity.User;
import cn.jjxx.modules.sys.utils.UserUtils;
import cn.jjxx.core.config.BillConfig;
import cn.jjxx.modules.screen.entity.BigScreenInfo;
import cn.jjxx.modules.screen.entity.BigScreenType;
import cn.jjxx.modules.screen.entity.ScreenInfo;
import cn.jjxx.modules.screen.service.IBigScreenTypeService;
import cn.jjxx.modules.map.service.ICommonMapService;
/**   
 * @Title: big_screen_type
 * @Description: big_screen_type
 * @author yx
 * @date 2022-05-07 09:40:13
 * @version V1.0   
 *
 */
@Controller
@RequestMapping("api/screenType") 
public class ScreenTypeApiController extends BaseBeanController<BigScreenType> {

    @Autowired
    protected IBigScreenTypeService bigScreenTypeService;
    @Autowired
    protected ICommonMapService commonMapService;

	/**
	 * @Description: 根据获取big_screen_type的实体数据 .<br>
	 * @param id 主键Id.<br>
	 * @author yx .<br>
	 * @date 2022-05-07 09:40:13.<br>
	 */
    public BigScreenType get(String id) {
        if (!ObjectUtils.isNullOrEmpty(id)) {
            return bigScreenTypeService.selectById(id);
        } else {
            return newModel();
        }
    }
    /**
     * 查询列表数据
    *@Title ScreenApiController.java
    *@description TODO
    *@time 2022年5月7日 上午11:43:55
    *@author YAOXIONG
    *@version 1.0
    *
     */
    @RequestMapping(value = "list")
    @ResponseBody   
    private void ajaxList(Queryable queryable, PropertyPreFilterable propertyPreFilterable,
    		HttpServletRequest request,
                          HttpServletResponse response) throws IOException {
        EntityWrapper<BigScreenType> entityWrapper = new EntityWrapper<BigScreenType>(entityClass);
        propertyPreFilterable.addQueryProperty("id");
         
        
        String pages = request.getParameter("page");
        
        entityWrapper.eq("delflag", 0)	;
        entityWrapper.orderBy("createTime", false);
        // 预处理
        QueryableConvertUtils.convertQueryValueToEntityValue(queryable, entityClass); 
        //拼接数据格式
        PageJson<BigScreenType> pagejson = new PageJson<BigScreenType>(bigScreenTypeService.list(pages,queryable,entityWrapper));
         
        JSONObject json = new JSONObject();
        json.put("page", pagejson.getPage()+1);
        json.put("pages", pagejson.getTotalPages());
        json.put("size",pagejson.getRows());
        json.put("total", pagejson.getTotal());
        json.put("list", pagejson.getResults());
        String content = JSON.toJSONString(json);
        StringUtils.printJson(response, content);
    }
    /**
     * 根据ID查询数据
    *@Title ScreenApiController.java
    *@description TODO
    *@time 2022年5月7日 下午12:24:02
    *@author YAOXIONG
    *@version 1.0
    *
     */
    @RequestMapping(value = "{id}")
    @ResponseBody   
    private void screenInfo(HttpServletRequest request,
                          HttpServletResponse response,@PathVariable("id") String screenId) throws IOException {
    	 
    	 String content = JSON.toJSONString(get(screenId));
         StringUtils.printJson(response, content);
    }
    
    /**
     * 根据类型查询 分类
    *@Title ScreenTypeApiController.java
    *@description TODO
    *@time 2022年5月7日 下午1:46:50
    *@author YAOXIONG
    *@version 1.0 
     */
    @RequestMapping(value = "selectByTypeId/{typeid}")
    @ResponseBody   
    private void selectByTypeId(HttpServletRequest request,
                          HttpServletResponse response,
                          @PathVariable("typeid") String typeid) throws IOException {
    	EntityWrapper<BigScreenType> entityWrapper = new EntityWrapper<BigScreenType>(entityClass);
    	entityWrapper.eq("dictype", typeid);  
    	JSONObject json = new JSONObject(); 
        json.put("list", bigScreenTypeService.selectList(entityWrapper));
        String content = JSON.toJSONString(json);
        StringUtils.printJson(response, content);
    }
}

